<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #search{
            border: solid 1px gray;
            padding: 10px;
            width: 500px;
            margin: 20px auto;
        }
        #search .s-top{
            margin-bottom: 10px;
        }
        #search .s-top input{
            width: 88%;
        }
        p{
            margin: 0px;
        }
        p>span{
            color: red;
        }
    </style>
</head>
<body>
    <div id="search">
        <div class="s-top">
            <input type="text" id="key">
            <button id="btnSearch">查询</button>
        </div>
        <p id="searchContent">
            打开就看读完了卡擦电脑卡没上课流程文件打开就看读完了卡擦电脑卡没上课流程文件打开就看读完了卡擦电脑卡没上课流程文件打开就看读完了卡擦电脑卡没上课流程文件打开就看读完了卡擦电脑卡没上课流程文件打开就看读完了卡擦电脑卡没上课流程文件
        </p>
    </div>
    <script>
        var $key=document.getElementById('key')
        var $btnSearch=document.getElementById('btnSearch')
        var $searchContent=document.getElementById('searchContent')
        $btnSearch.onclick=function(){
            var newP=searchByStr($key.value)
            $searchContent.innerHTML=newP
        }

        // 查询函数
        function searchByStr(key) {
            var reg=new RegExp(key,'g')
            var newP=$searchContent.innerHTML.replace(reg,'<span>'+key+'</span>')
            return newP
        }
    </script>
</body>
</html>